# -*- coding:utf-8 -*-
class Solution:
    def Permutation(self, ss):
        # write code here

        if len(ss) == 1:
            return [ss]
        ls = []
        for i in range(len(ss)):
            for j in self.Permutation(ss[:i] + ss[i + 1:]):
                ls.append(ss[i] + j)
        return sorted(list(set(ls)))

    # 扩展习题, 生成字符的所有组合
    # 比如输入abc, 则他们的组合有['a', 'ab', 'abc', 'ac', 'b', 'bc', 'c'],
    # ab和ba属于不同的排列, 但属于同一个组合
    def group(self, ss):
        if not len(ss):
            return []
        if len(ss) == 1:
            return list(ss)
        charList = list(ss)
        charList.sort()
        p = []
        for i in range(len(charList)):
            p.append(charList[i])
            temp =  self.group(''.join(charList[i + 1:]))
            for j in temp:
                p.append(ss[i]+j)
            pStr = list(set(p))
            pStr.sort()
        return pStr



ss = 'acb'
S = Solution()
print(S.Permutation(ss))
print(S.group(ss))
